"Colin's filetype options vimrc

"Turn on filetype detection
"filetype on
"Turn on filetype detection (with filetype plugins)
filetype plugin on

"Create an autocmd group so that re-sourcing the vimrc does not
"multiply define autocmds
augroup MyAutoCmdGroup
   "Remove all autocmds for this group to start from scratch
   autocmd! MyAutoCmdGroup

   autocmd FileType c,cpp     call FtCOrCpp()
   autocmd FileType python    call FtPython()
   autocmd FileType perl      call FtPerl()
   autocmd FileType matlab    call FtMatlab()
   autocmd FileType make      call FtMake()
   autocmd FileType vim       call FtVim()
   autocmd FileType cstol     call FtCstol()
   autocmd FileType dosbatch  call FtDosBatch()
   autocmd FileType vb        call FtVisualBasic()
   autocmd FileType asm,inc   call FtAsm()
   autocmd FileType html,htm  call FtHtml()

augroup END


"My formatting preferences for code, makefiles, etc.
function! MyFormattingPreferences()
   set formatoptions-=t formatoptions+=rl
   set showmatch
   if &readonly
      set nolist
   else
      set list
   endif
   "Printing options (print via :hardcopy)
   set printoptions=number:y,left:5pc,syntax:n
endfunction

function! FtCOrCpp()
   call MyFormattingPreferences()
   "Turn on c-indenting (customizable via cinoptions)
   set cindent
   "C-Indent options
   "  (0  - indent to column of open paren
   "  W2s - clarify '(0' to use 2*shiftwidth if last char above is open paren
   "  )N  - search for closing parens at most N lines away (default 20)
   "  *N  - search for comments most N lines away (default 30)
   "  g0  - Place C++ scope declarations 0 chars from their indent block
   set cinoptions=(0,W2s,)100,*100,g0
   "Prevent entering of # at the beginning of the line from indenting to col 0
   set cinkeys-=0#
   "Set up tabs to only be 3 spaces
   set tabstop=3 shiftwidth=3 expandtab smarttab
   "set comments=sr:/*,mb:**,el:*/,://
   "set comments=sr:/*,mb:*,el:*/,://
   "Comments set up for C style to be Doxygen style
   set comments=s1l:/**,mb:*,ex:*/,://,s1l:/*,mb:*,ex:*/
   set keywordprg=man

   "insert main function
   imap Zmain  int main(int argc, char *argv[])<ESC>o{<ESC>o}<ESC>O
   "insert #define at start of line
   imap Zdef   <ESC>0i#define<SPACE>
   "insert #include at start of line
   imap Zinc   <ESC>0i#include<SPACE>

   "insert "if" statement
   imap Zif    if ()<ESC>o{<ESC>o}<ESC>O<ESC>2k$i
   "insert else clause of if statement with following if statement
   imap Zelif  else if ()<ESC>o{<ESC>o}<ESC>O<ESC>2k$i
   "insert else clause of if statement
   imap Zelse  else<ESC>o{<ESC>o}<ESC>O

   "insert "for" statement
   imap Zfor   for (;;)<ESC>o{<ESC>o}<ESC>O<ESC>2kla
   "insert "while" statement
   imap Zwhile while ()<ESC>o{<ESC>o}<ESC>O<ESC>2k$i

   "insert comment block
   "imap Zcom   /<ESC>77a*<ESC>o<CR><ESC>76a*<ESC>a/<ESC>kO<CR><BS>
   "insert brackets for statement list
   "imap <C-A> o{<ESC>o}<ESC>O
endfunction


function! FtPython()
   call MyFormattingPreferences()

   setlocal smartindent
   "Special treatment for smartindent to not putting # at the first column
   "See 'help smartindent'
   inoremap # X#
   "If I was using cindent, I think I would want this:
   "Prevent entering of # at the beginning of the line from indenting to col 0
   setlocal cinkeys-=0#

   "Set up tabs to only be 4 spaces
   setlocal tabstop=4 shiftwidth=4 expandtab smarttab
   setlocal comments=:#
   " Temporarily here, need to consider re-working the way
   " I do these options!  Look at help for this, and related topics...
   "filetype indent on
endfunction


function! FtPerl()
   call MyFormattingPreferences()

   " set smartindent
   " "Special treatment for smartindent to not putting # at the first column
   " "See 'help smartindent'
   " inoremap # X#

   "Turn on c-indenting (customizable via cinoptions)
   set cindent
   "C-Indent options
   "  (0  - indent to column of open paren
   "  W2s - clarify '(0' to use 2*shiftwidth if last char above is open paren
   "  )N  - search for closing parens at most N lines away (default 20)
   "  *N  - search for comments most N lines away (default 30)
   "  g0  - Place C++ scope declarations 0 chars from their indent block
   set cinoptions=(0,W2s,)100,*100,g0
   "Prevent entering of # at the beginning of the line from indenting to col 0
   set cinkeys-=0#

   "Set up tabs to only be 3 spaces
   set tabstop=3 shiftwidth=3 expandtab smarttab

   set comments=:#

   "Note - this won't work completely right, but it'll bring up man perlfunc
   set keywordprg=man\ perlfunc
endfunction


function! FtMatlab()
   call MyFormattingPreferences()
   set cindent
   "Set up tabs to only be 3 spaces
   set tabstop=3 shiftwidth=3 expandtab smarttab
   set comments=:%
   "set keywordprg=man
endfunction

function! FtMake()
   call MyFormattingPreferences()
   set cindent
   set noexpandtab shiftwidth=3 tabstop=3 softtabstop=0
   "set comments=:#menucfg\|,:#helpcfg\|,:#
   set comments=:#
   set keywordprg=man
endfunction

function! FtVim()
   call MyFormattingPreferences()
   set tabstop=3 shiftwidth=3 expandtab smarttab
   set smartindent
   set comments=:\"
   set keywordprg=:help
   set fileformat=unix
endfunction

function! FtCstol()
   call MyFormattingPreferences()
   set smartindent
   "Set up tabs to only be 2 spaces
   set tabstop=2 shiftwidth=2 expandtab smarttab
   set comments=:;
   "set keywordprg=man
   "cstol scripts must have unix EOLs
   set fileformat=unix
endfunction

function! FtEmail()
   set formatoptions+=raw
   set textwidth=72
   "set keywordprg=webster
   "
   "       ,dt = "date and time insert"
   "map     ,dt :r!date +\%y\%m\%d\%t\%T<CR>
   "       ,da = date insert (the way I like it)
   "map     ,da :r!date '+\%e \%B \%Y'<CR>
   "
   "ab Yurl  http://thinker.colorado.edu/~grahamca/contact.html
   "ab Yres  http://thinker.colorado.edu/~grahamca/resume_toc.html
   "ab Ytbp  http://ucsub.colorado.edu/~tbp/initiate.html
   "
   "map ,s = :r ~/.signature-tbp.advisor
   "map ,a = :r ~/.signature-all
   "map ,i = :r ~/.signature-ieee
endfunction

function! FtDosBatch()
   call MyFormattingPreferences()
   set smartindent
   "Set up tabs to only be 3 spaces
   set tabstop=3 shiftwidth=3 expandtab smarttab
   set comments=b:rem,b:REM
endfunction

function! FtVisualBasic()
   call MyFormattingPreferences()
   set tabstop=3 shiftwidth=3 expandtab smarttab
   set autoindent
   "set smartindent
   setlocal ignorecase "VBScript is a case-insensitive language
endfunction

function! FtAsm()
   call MyFormattingPreferences()
   "Turn on c-indenting (customizable via cinoptions)
   set cindent
   "C-Indent options
   "  (0  - indent to column of open paren
   "  W2s - clarify '(0' to use 2*shiftwidth if last char above is open paren
   "  )N  - search for closing parens at most N lines away (default 20)
   "  *N  - search for comments most N lines away (default 30)
   "  g0  - Place C++ scope declarations 0 chars from their indent block
   set cinoptions=(0,W2s,)100,*100,g0
   "Prevent entering of # at the beginning of the line from indenting to col 0
   set cinkeys-=0#
   "Set up tabs to only be 3 spaces, except tabs are 8
   set tabstop=8 shiftwidth=3 expandtab smarttab
   "set comments=sr:/*,mb:**,el:*/,://
   "set comments=sr:/*,mb:*,el:*/,://
   "Comments set up for C style to be Doxygen style
   "set comments=s1l:/**,mb:*,ex:*/,://,s1l:/*,mb:*,ex:*/
   "set keywordprg=man

endfunction

function! FtHtml()
   call MyFormattingPreferences()
   set tabstop=2 shiftwidth=2 expandtab smarttab
endfunction

